class Solution {
    public:
        int numberOfArrays(vector<int>& differences, int lower, int upper) {
            int ans=0;
            long long init=lower;
            long long Max=lower;
            long long Min=upper;
            for(int i=0;i<differences.size();i++){
                init+=differences[i];
                Max=max(Max,init);//找到初始区间最大值
                Min=min(Min,init);//找到初始区间最小值
            }
            while(Max<=upper){
                if(Max<=upper&&Min>=lower){
                    ans++;
                    break;
                }
                Max++;
                Min++;
            }
            ans+=upper-Max;
            if(ans<=0){
                return 0;
            }
            return ans;
        }
    };